home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Admin / ad_groups.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  32.7 KB  |  1,082 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Admin Forum functions
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 17th March 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25.  
  26.  
  27. $idx = new ad_groups();
  28.  
  29.  
  30. class ad_groups {
  31.  
  32.     var $base_url;
  33.  
  34.     function ad_groups() {
  35.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  36.  
  37.         switch($IN['code'])
  38.         {
  39.             case 'doadd':
  40.                 $this->save_group('add');
  41.                 break;
  42.                 
  43.             case 'add':
  44.                 $this->group_form('add');
  45.                 break;
  46.                 
  47.             case 'edit':
  48.                 $this->group_form('edit');
  49.                 break;
  50.             
  51.             case 'doedit':
  52.                 $this->save_group('edit');
  53.                 break;
  54.             
  55.             case 'delete':
  56.                 $this->delete_form();
  57.                 break;
  58.             
  59.             case 'dodelete':
  60.                 $this->do_delete();
  61.                 break;
  62.                 
  63.             case 'fedit':
  64.                 $this->forum_perms();
  65.                 break;
  66.                 
  67.             case 'dofedit':
  68.                 $this->do_forum_perms();
  69.                 break;
  70.                         
  71.             default:
  72.                 $this->main_screen();
  73.                 break;
  74.         }
  75.         
  76.     }
  77.     
  78.     
  79.     //+---------------------------------------------------------------------------------
  80.     //
  81.     // Delete a group
  82.     //
  83.     //+---------------------------------------------------------------------------------
  84.     
  85.     function forum_perms()
  86.     {
  87.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  88.         
  89.         if ($IN['id'] == "")
  90.         {
  91.             $ADMIN->error("Could not resolve the group ID, please try again");
  92.         }
  93.         
  94.         //+----------------------------------
  95.         
  96.         $ADMIN->page_title = "User Group Forum Access Permissions";
  97.         
  98.         $ADMIN->page_detail = "This is a quick and convenient way to organise forum access for this member group. If you wish to change multiple group permissions, then you may wish to do so from forum management.<br><br>Simply check the box in the start column if you wish to allow that member group to start new topics in that forum, etc.<br><b>Global</b> indictates that the forum is set to allow all member groups to carry out that action. If you wish to change this, do so from forum control.";
  99.         
  100.         //+----------------------------------
  101.         
  102.         $DB->query("SELECT g_title, g_id FROM ibf_groups WHERE g_id='".$IN['id']."'");
  103.         $group = $DB->fetch_row();
  104.         
  105.         $gid = $group['g_id'];
  106.         
  107.         //+-------------------------------
  108.         
  109.         $cats     = array();
  110.         $forums   = array();
  111.         $children = array();
  112.         
  113.         $DB->query("SELECT * from ibf_categories WHERE id > 0 ORDER BY position ASC");
  114.         while ($r = $DB->fetch_row())
  115.         {
  116.             $cats[$r['id']] = $r;
  117.         }
  118.         
  119.         $DB->query("SELECT * from ibf_forums ORDER BY position ASC");
  120.         while ($r = $DB->fetch_row())
  121.         {
  122.             
  123.             if ($r['parent_id'] > 0)
  124.             {
  125.                 $children[ $r['parent_id'] ][] = $r;
  126.             }
  127.             else
  128.             {
  129.                 $forums[] = $r;
  130.             }
  131.             
  132.         }
  133.         
  134.         //+----------------------------------
  135.         
  136.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'dofedit' ),
  137.                                                   2 => array( 'act'   , 'group'   ),
  138.                                                   3 => array( 'id'    , $gid      ),
  139.                                          )      );
  140.         
  141.         $SKIN->td_header[] = array( "Forum Name"   , "35%" );
  142.         $SKIN->td_header[] = array( "Posts"        , "10%" );
  143.         $SKIN->td_header[] = array( "Topics"       , "10%" );
  144.         $SKIN->td_header[] = array( "Start"        , "15%" );
  145.         $SKIN->td_header[] = array( "Reply"        , "15%" );
  146.         $SKIN->td_header[] = array( "Read"         , "15%" );
  147.         
  148.         $ADMIN->html .= $SKIN->start_table( "Forum Access for ".$group['g_title'] );
  149.         
  150.         $last_cat_id = -1;
  151.         
  152.         foreach ($cats as $c)
  153.         {
  154.             
  155.             $ADMIN->html .= $SKIN->add_td_basic( $c['name'], 'center', 'catrow' );
  156.                                                        
  157.             $last_cat_id = $c['id'];
  158.             
  159.             
  160.             foreach($forums as $r)
  161.             {    
  162.             
  163.                 if ($r['category'] == $last_cat_id)
  164.                 {
  165.                 
  166.                     $read   = "";
  167.                     $start  = "";
  168.                     $reply  = "";
  169.                     $global = '<center><i>Global</i></center>';
  170.                     
  171.                     if ($r['read_perms'] == '*')
  172.                     {
  173.                         $read = $global;
  174.                     }
  175.                     else if ( preg_match( "/(^|,)".$gid."(,|$)/", $r['read_perms'] ) )
  176.                     {
  177.                         $read = "<center><input type='checkbox' name='read_".$r['id']."' value='1' checked></center>";
  178.                     }
  179.                     else
  180.                     {
  181.                         $read = "<center><input type='checkbox' name='read_".$r['id']."' value='1'></center>";
  182.                     }
  183.                     
  184.                     //---------------------------
  185.                     
  186.                     if ($r['start_perms'] == '*')
  187.                     {
  188.                         $start = $global;
  189.                     }
  190.                     else if ( preg_match( "/(^|,)".$gid."(,|$)/", $r['start_perms'] ) )
  191.                     {
  192.                         $start = "<center><input type='checkbox' name='start_".$r['id']."' value='1' checked></center>";
  193.                     }
  194.                     else
  195.                     {
  196.                         $start = "<center><input type='checkbox' name='start_".$r['id']."' value='1'></center>";
  197.                     }
  198.                     
  199.                     //---------------------------
  200.                     
  201.                     if ($r['reply_perms'] == '*')
  202.                     {
  203.                         $reply = $global;
  204.                     }
  205.                     else if ( preg_match( "/(^|,)".$gid."(,|$)/", $r['reply_perms'] ) )
  206.                     {
  207.                         $reply = "<center><input type='checkbox' name='reply_".$r['id']."' value='1' checked></center>";
  208.                     }
  209.                     else
  210.                     {
  211.                         $reply = "<center><input type='checkbox' name='reply_".$r['id']."' value='1'></center>";
  212.                     }
  213.                     
  214.                     //---------------------------
  215.                     
  216.                     if ($r['subwrap'] == 1)
  217.                     {
  218.                         $ADMIN->html .= $SKIN->add_td_basic( "> ".$r['name'], 'left', 'catrow2' );
  219.                     }
  220.                     else
  221.                     {
  222.                         $ADMIN->html .= $SKIN->add_td_row( array(
  223.                                                                "<b>".$r['name']."</b><br>".$r['description'],
  224.                                                                "<center>".$r['posts']."</center>",
  225.                                                                "<center>".$r['topics']."</center>",
  226.                                                                $start,
  227.                                                                $reply,
  228.                                                                $read
  229.                                                      )      );
  230.                     }
  231.                                                      
  232.                     if ( ( isset($children[ $r['id'] ]) ) and ( count ($children[ $r['id'] ]) > 0 ) )
  233.                     {
  234.                         foreach($children[ $r['id'] ] as $idx => $rd)
  235.                         {
  236.                             $read   = "";
  237.                             $start  = "";
  238.                             $reply  = "";
  239.                             $global = '<center><i>Global</i></center>';
  240.                             
  241.                             if ($rd['read_perms'] == '*')
  242.                             {
  243.                                 $read = $global;
  244.                             }
  245.                             else if ( preg_match( "/(^|,)".$gid."(,|$)/", $rd['read_perms'] ) )
  246.                             {
  247.                                 $read = "<center><input type='checkbox' name='read_".$rd['id']."' value='1' checked></center>";
  248.                             }
  249.                             else
  250.                             {
  251.                                 $read = "<center><input type='checkbox' name='read_".$rd['id']."' value='1'></center>";
  252.                             }
  253.                             
  254.                             //---------------------------
  255.                             
  256.                             if ($rd['start_perms'] == '*')
  257.                             {
  258.                                 $start = $global;
  259.                             }
  260.                             else if ( preg_match( "/(^|,)".$gid."(,|$)/", $rd['start_perms'] ) )
  261.                             {
  262.                                 $start = "<center><input type='checkbox' name='start_".$rd['id']."' value='1' checked></center>";
  263.                             }
  264.                             else
  265.                             {
  266.                                 $start = "<center><input type='checkbox' name='start_".$rd['id']."' value='1'></center>";
  267.                             }
  268.                             
  269.                             //---------------------------
  270.                             
  271.                             if ($rd['reply_perms'] == '*')
  272.                             {
  273.                                 $reply = $global;
  274.                             }
  275.                             else if ( preg_match( "/(^|,)".$gid."(,|$)/", $rd['reply_perms'] ) )
  276.                             {
  277.                                 $reply = "<center><input type='checkbox' name='reply_".$rd['id']."' value='1' checked></center>";
  278.                             }
  279.                             else
  280.                             {
  281.                                 $reply = "<center><input type='checkbox' name='reply_".$rd['id']."' value='1'></center>";
  282.                             }
  283.                             
  284.                             //---------------------------
  285.                     
  286.                             $ADMIN->html .= $SKIN->add_td_row( array(
  287.                                                                "<b>".$rd['name']."</b><br>".$rd['description'],
  288.                                                                "<center>".$rd['posts']."</center>",
  289.                                                                "<center>".$rd['topics']."</center>",
  290.                                                                $start,
  291.                                                                $reply,
  292.                                                                $read
  293.                                                      ) , 'subforum'     );
  294.                         }
  295.                     }                     
  296.                 }
  297.             }
  298.         }
  299.         
  300.         $ADMIN->html .= $SKIN->end_form("Update Forum Permissions");
  301.         
  302.         $ADMIN->html .= $SKIN->end_table();
  303.         
  304.         $ADMIN->output();
  305.         
  306.     }
  307.     
  308.     function do_forum_perms()
  309.     {
  310.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  311.         
  312.         //---------------------------
  313.         // Check for legal ID
  314.         //---------------------------
  315.         
  316.         if ($IN['id'] == "")
  317.         {
  318.             $ADMIN->error("Could not resolve that group ID");
  319.         }
  320.         
  321.         $gid = $IN['id'];
  322.         
  323.         //---------------------------
  324.         
  325.         $DB->query("SELECT g_id FROM ibf_groups WHERE g_id='".$IN['id']."'");
  326.         
  327.         if ( ! $DB->get_num_rows() )
  328.         {
  329.             $ADMIN->error("Not a valid group ID");
  330.         }
  331.         
  332.         //---------------------------
  333.         // Pull the forum data..
  334.         //---------------------------
  335.         
  336.         $forum_q = $DB->query("SELECT id, read_perms, start_perms, reply_perms FROM ibf_forums ORDER BY position ASC");
  337.         
  338.         while ( $row = $DB->fetch_row( $forum_q ) )
  339.         {
  340.         
  341.             $read  = "";
  342.             $reply = "";
  343.             $start = "";
  344.             //---------------------------
  345.             // Is this global?
  346.             //---------------------------
  347.             
  348.             if ($row['read_perms'] == '*')
  349.             {
  350.                 $read = '*';
  351.                 
  352.             }
  353.             else
  354.             {
  355.                 //---------------------------
  356.                 // Split the set IDs
  357.                 //---------------------------
  358.                 
  359.                 $read_ids = explode( ",", $row['read_perms'] );
  360.                 
  361.                 if ( is_array($read_ids) )
  362.                 {
  363.                    foreach ($read_ids as $i)
  364.                    {
  365.                        //---------------------------
  366.                        // If it's the current ID, skip
  367.                        //---------------------------
  368.                        
  369.                        if ($gid == $i)
  370.                        {
  371.                            continue;
  372.                        }
  373.                        else
  374.                        {
  375.                            $read .= $i.",";
  376.                        }
  377.                    }
  378.                 }
  379.                 //---------------------------
  380.                 // Was the box checked?
  381.                 //---------------------------
  382.                 
  383.                 if ($IN[ 'read_'.$row['id'] ] == 1)
  384.                 {
  385.                     // Add our group ID...
  386.                     
  387.                     $read .= $gid.",";
  388.                 }
  389.                 
  390.                 // Tidy..
  391.                 
  392.                 $read = preg_replace( "/,$/", "", $read );
  393.                 $read = preg_replace( "/^,/", "", $read );
  394.                 
  395.             }
  396.             
  397.             //---------------------------
  398.             // Reply topics..
  399.             //---------------------------
  400.                 
  401.             if ($row['reply_perms'] == '*')
  402.             {
  403.                 $reply = '*';
  404.             }
  405.             else
  406.             {
  407.                 $reply_ids = explode( ",", $row['reply_perms'] );
  408.                 
  409.                 if ( is_array($reply_ids) )
  410.                 {
  411.                 
  412.                     foreach ($reply_ids as $i)
  413.                     {
  414.                         if ($gid == $i)
  415.                         {
  416.                             continue;
  417.                         }
  418.                         else
  419.                         {
  420.                             $reply .= $i.",";
  421.                         }
  422.                     }
  423.                 
  424.                 }
  425.                 
  426.                 if ($IN[ 'reply_'.$row['id'] ] == 1)
  427.                 {
  428.                     $reply .= $gid.",";
  429.                 }
  430.                 
  431.                 $reply = preg_replace( "/,$/", "", $reply );
  432.                 $reply = preg_replace( "/^,/", "", $reply );
  433.             }
  434.             
  435.             //---------------------------
  436.             // Start topics..
  437.             //---------------------------
  438.                 
  439.             if ($row['start_perms'] == '*')
  440.             {
  441.                 $start = '*';
  442.             }
  443.             else
  444.             {
  445.                 $start_ids = explode( ",", $row['start_perms'] );
  446.                 
  447.                 if ( is_array($start_ids) )
  448.                 {
  449.                 
  450.                     foreach ($start_ids as $i)
  451.                     {
  452.                         if ($gid == $i)
  453.                         {
  454.                             continue;
  455.                         }
  456.                         else
  457.                         {
  458.                             $start .= $i.",";
  459.                         }
  460.                     }
  461.                 
  462.                 }
  463.                 
  464.                 if ($IN[ 'start_'.$row['id'] ] == 1)
  465.                 {
  466.                     $start .= $gid.",";
  467.                 }
  468.                 
  469.                 $start = preg_replace( "/,$/", "", $start );
  470.                 $start = preg_replace( "/^,/", "", $start );
  471.             }
  472.             
  473.             //---------------------------
  474.             // Update the DB...
  475.             //---------------------------
  476.             
  477.             if (! $new_q = $DB->query("UPDATE ibf_forums SET read_perms='$read', reply_perms='$reply', start_perms='$start' WHERE id='".$row['id']."'") )
  478.             {
  479.                 die ("Update query failed on Forum ID ".$row['id']);
  480.             }
  481.             
  482.         }
  483.         
  484.         $ADMIN->done_screen("Forum Access Permissions Updated", "Group Control", "act=group" );
  485.         
  486.     }
  487.     
  488.     //+---------------------------------------------------------------------------------
  489.     //
  490.     // Delete a group
  491.     //
  492.     //+---------------------------------------------------------------------------------
  493.     
  494.     function delete_form()
  495.     {
  496.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  497.         
  498.         if ($IN['id'] == "")
  499.         {
  500.             $ADMIN->error("Could not resolve the group ID, please try again");
  501.         }
  502.         
  503.         if ($IN['id'] < 5)
  504.         {
  505.             $ADMIN->error("You can not move the preset groups. You can rename them and edit the functionality");
  506.         }
  507.         
  508.         $ADMIN->page_title = "Deleting a User Group";
  509.         
  510.         $ADMIN->page_detail = "Please check to ensure that you are attempting to remove the correct group.";
  511.         
  512.         
  513.         //+-------------------------------
  514.         
  515.         $DB->query("SELECT COUNT(id) as users FROM ibf_members WHERE mgroup='".$IN['id']."'");
  516.         $black_adder = $DB->fetch_row();
  517.         
  518.         if ($black_adder['users'] < 1)
  519.         {
  520.             $black_adder['users'] = 0;
  521.         }
  522.         
  523.         $DB->query("SELECT g_title FROM ibf_groups WHERE g_id='".$IN['id']."'");
  524.         $group = $DB->fetch_row();
  525.         
  526.         //+-------------------------------
  527.         
  528.         $DB->query("SELECT g_id, g_title FROM ibf_groups WHERE g_id <> '".$IN['id']."'");
  529.         
  530.         $mem_groups = array();
  531.         
  532.         while ( $r = $DB->fetch_row() )
  533.         {
  534.             $mem_groups[] = array( $r['g_id'], $r['g_title'] );
  535.         }
  536.         
  537.         //+-------------------------------
  538.         
  539.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'dodelete'  ),
  540.                                                   2 => array( 'act'   , 'group'     ),
  541.                                                   3 => array( 'id'    , $IN['id']   ),
  542.                                          )      );
  543.                                          
  544.         
  545.         
  546.         //+-------------------------------
  547.         
  548.         $SKIN->td_header[] = array( " "  , "40%" );
  549.         $SKIN->td_header[] = array( " "  , "60%" );
  550.         
  551.         //+-------------------------------
  552.         
  553.         $ADMIN->html .= $SKIN->start_table( "Removal Confirmation: ".$group['g_title'] );
  554.         
  555.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Number of users in this group</b>" ,
  556.                                                   "<b>".$black_adder['users']."</b>",
  557.                                          )      );
  558.                                          
  559.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Move users in this group to...</b>" ,
  560.                                                   $SKIN->form_dropdown("to_id", $mem_groups )
  561.                                          )      );
  562.         
  563.         $ADMIN->html .= $SKIN->end_form("Delete this group");
  564.                                          
  565.         $ADMIN->html .= $SKIN->end_table();
  566.         
  567.         $ADMIN->output();
  568.             
  569.             
  570.     }
  571.     
  572.     function do_delete()
  573.     {
  574.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  575.         
  576.         if ($IN['id'] == "")
  577.         {
  578.             $ADMIN->error("Could not resolve the group ID, please try again");
  579.         }
  580.         
  581.         if ($IN['to_id'] == "")
  582.         {
  583.             $ADMIN->error("No move to group ID was specified. /me cries.");
  584.         }
  585.         
  586.         // Check to make sure that the relevant groups exist.
  587.         
  588.         $DB->query("SELECT g_id FROM ibf_groups WHERE g_id IN(".$IN['id'].",".$IN['to_id'].")");
  589.         
  590.         if ( $DB->get_num_rows() != 2 )
  591.         {
  592.             $ADMIN->error("Could not resolve the ID's passed to group deletion");
  593.         }
  594.         
  595.         $DB->query("UPDATE ibf_members SET mgroup='".$IN['to_id']."' WHERE mgroup='".$IN['id']."'");
  596.         
  597.         $DB->query("DELETE FROM ibf_groups WHERE g_id='".$IN['id']."'");
  598.         
  599.         $ADMIN->done_screen("Group Removed", "Group Control", "act=group" );
  600.         
  601.     }
  602.     
  603.     
  604.     //+---------------------------------------------------------------------------------
  605.     //
  606.     // Save changes to DB
  607.     //
  608.     //+---------------------------------------------------------------------------------
  609.     
  610.     function save_group($type='edit')
  611.     {
  612.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  613.         
  614.         if ($IN['g_title'] == "")
  615.         {
  616.             $ADMIN->error("You must enter a group title.");
  617.         }
  618.         
  619.         if ($type == 'edit')
  620.         {
  621.             if ($IN['id'] == "")
  622.             {
  623.                 $ADMIN->error("Could not resolve the group id");
  624.             }
  625.             
  626.             if ($IN['id'] == $INFO['admin_group'] and $IN['g_access_cp'] != 1)
  627.             {
  628.                 $ADMIN->error("You can not remove the ability to access the admin control panel for this group");
  629.             }
  630.         }
  631.         
  632.         // Build up the hashy washy for the database ..er.. wase.
  633.         
  634.         $prefix = preg_replace( "/'/", "'" , stripslashes($HTTP_POST_VARS['prefix']) );
  635.         $prefix = preg_replace( "/</" , "<" , $prefix          );
  636.         $suffix = preg_replace( "/'/", "'" , stripslashes($HTTP_POST_VARS['suffix']) );
  637.         $suffix = preg_replace( "/</" , "<" , $suffix          );
  638.         
  639.         $db_string = array(
  640.                              'g_view_board'         => $IN['g_view_board'],
  641.                              'g_mem_info'           => $IN['g_mem_info'],
  642.                              'g_other_topics'       => $IN['g_other_topics'],
  643.                              'g_use_search'         => $IN['g_use_search'],
  644.                              'g_email_friend'       => $IN['g_email_friend'],
  645.                              'g_invite_friend'      => $IN['g_invite_friend'],
  646.                              'g_edit_profile'       => $IN['g_edit_profile'],
  647.                              'g_post_new_topics'    => $IN['g_post_new_topics'],
  648.                              'g_reply_own_topics'   => $IN['g_reply_own_topics'],
  649.                              'g_reply_other_topics' => $IN['g_reply_other_topics'],
  650.                              'g_edit_posts'         => $IN['g_edit_posts'],
  651.                              'g_delete_own_posts'   => $IN['g_delete_own_posts'],
  652.                              'g_open_close_posts'   => $IN['g_open_close_posts'],
  653.                              'g_delete_own_topics'  => $IN['g_delete_own_topics'],
  654.                              'g_post_polls'         => $IN['g_post_polls'],
  655.                              'g_vote_polls'         => $IN['g_vote_polls'],
  656.                              'g_use_pm'             => $IN['g_use_pm'],
  657.                              'g_is_supmod'          => $IN['g_is_supmod'],
  658.                              'g_access_cp'          => $IN['g_access_cp'],
  659.                              'g_title'              => trim($IN['g_title']),
  660.                              'g_can_remove'         => $IN['g_can_remove'],
  661.                              'g_append_edit'        => $IN['g_append_edit'],
  662.                              'g_access_offline'     => $IN['g_access_offline'],
  663.                              'g_avoid_q'            => $IN['g_avoid_q'],
  664.                              'g_avoid_flood'        => $IN['g_avoid_flood'],
  665.                              'g_icon'               => trim($IN['g_icon']),
  666.                              'g_attach_max'         => $IN['g_attach_max'],
  667.                              'g_avatar_upload'      => $IN['g_avatar_upload'],
  668.                              'g_calendar_post'      => $IN['g_calendar_post'],
  669.                              'prefix'               => $prefix,
  670.                              'suffix'               => $suffix
  671.                              
  672.                           );
  673.                           
  674.         if ($type == 'edit')
  675.         {
  676.             $rstring = $DB->compile_db_update_string( $db_string );
  677.             
  678.             $DB->query("UPDATE ibf_groups SET $rstring WHERE g_id='".$IN['id']."'");
  679.             
  680.             $ADMIN->done_screen("Group Edited", "Group Control", "act=group" );
  681.             
  682.         }
  683.         else
  684.         {
  685.             $rstring = $DB->compile_db_insert_string( $db_string );
  686.             
  687.             $DB->query("INSERT INTO ibf_groups (" .$rstring['FIELD_NAMES']. ") VALUES (". $rstring['FIELD_VALUES'] .")");
  688.             
  689.             $ADMIN->done_screen("Group Added", "Group Control", "act=group" );
  690.         }
  691.     }
  692.     
  693.     
  694.     //+---------------------------------------------------------------------------------
  695.     //
  696.     // Add / edit group
  697.     //
  698.     //+---------------------------------------------------------------------------------
  699.     
  700.     function group_form($type='edit')
  701.     {
  702.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  703.         
  704.         if ($type == 'edit')
  705.         {
  706.             if ($IN['id'] == "")
  707.             {
  708.                 $ADMIN->error("No group id to select from the database, please try again.");
  709.             }
  710.             
  711.             $form_code = 'doedit';
  712.             $button    = 'Complete Edit';
  713.                 
  714.         }
  715.         else
  716.         {
  717.             $form_code = 'doadd';
  718.             $button    = 'Add Group';
  719.         }
  720.         
  721.         if ($IN['id'] != "")
  722.         {
  723.             $DB->query("SELECT * FROM ibf_groups WHERE g_id='".$IN['id']."'");
  724.             $group = $DB->fetch_row();
  725.         }
  726.         else
  727.         {
  728.             $group = array();
  729.         }
  730.         
  731.         if ($type == 'edit')
  732.         {
  733.             $ADMIN->page_title = "Editing User Group ".$group['g_title'];
  734.         }
  735.         else
  736.         {
  737.             $ADMIN->page_title = 'Adding a new user group';
  738.             $group['g_title'] = 'New Group';
  739.         }
  740.         
  741.         $guest_legend = "";
  742.         
  743.         if ($group['g_id'] == $INFO['guest_group'])
  744.         {
  745.             $guest_legend = "</b><br><i>(Does not apply to guests)</i>";
  746.         }
  747.         
  748.         $ADMIN->page_detail = "Please double check the information before submitting the form.";
  749.         
  750.         
  751.         //+-------------------------------
  752.         
  753.         $ADMIN->html .= "<script language='javascript'>
  754.                          <!--
  755.                           function checkform() {
  756.                           
  757.                               isAdmin = document.forms[0].g_access_cp;
  758.                               isMod   = document.forms[0].g_is_supmod;
  759.                               
  760.                               msg = '';
  761.                               
  762.                               if (isAdmin[0].checked == true)
  763.                               {
  764.                                   msg += 'Members in this group can access the Admin Control Panel\\n\\n';
  765.                               }
  766.                               
  767.                               if (isMod[0].checked == true)
  768.                               {
  769.                                   msg += 'Members in this group are super moderators.\\n\\n';
  770.                               }
  771.                               
  772.                               if (msg != '')
  773.                               {
  774.                                   msg = 'Security Check\\n--------------\\nMember Group Title: ' + document.forms[0].g_title.value + '\\n--------------\\n\\n' + msg + 'Is this correct?';
  775.                                   
  776.                                   formCheck = confirm(msg);
  777.                                   
  778.                                   if (formCheck == true)
  779.                                   {
  780.                                       return true;
  781.                                   }
  782.                                   else
  783.                                   {
  784.                                       return false;
  785.                                   }
  786.                               }
  787.                           }
  788.                          //-->
  789.                          </script>\n";
  790.         
  791.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , $form_code  ),
  792.                                                   2 => array( 'act'   , 'group'     ),
  793.                                                   3 => array( 'id'    , $IN['id']   ),
  794.                                          ) , 'adform', "onSubmit='return checkform()'" );
  795.                                          
  796.         
  797.         
  798.         //+-------------------------------
  799.         
  800.         $SKIN->td_header[] = array( " "  , "40%" );
  801.         $SKIN->td_header[] = array( " "  , "60%" );
  802.         
  803.         //+-------------------------------
  804.         
  805.         $prefix = preg_replace( "/'/", "'", $group['prefix'] );
  806.         $prefix = preg_replace( "/</", "<" , $prefix          );
  807.         $suffix = preg_replace( "/'/", "'", $group['suffix'] );
  808.         $suffix = preg_replace( "/</", "<" , $suffix          );
  809.         
  810.         $ADMIN->html .= $SKIN->start_table( "Global Settings" );
  811.         
  812.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Group Title</b>" ,
  813.                                                   $SKIN->form_input("g_title", $group['g_title'] )
  814.                                          )      );
  815.                                          
  816.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Group Icon</b><br>(Can be omitted)" ,
  817.                                                   $SKIN->form_input("g_icon", $group['g_icon'] )
  818.                                          )      );
  819.         
  820.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Max upload file size (in KB)</b><br>(Leave blank to disallow uploads)" ,
  821.                                                   $SKIN->form_input("g_attach_max", $group['g_attach_max'] )
  822.                                          )      );
  823.                                          
  824.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Online List Format [Prefix]</b><br>(Can be left blank)<br>(Example:<span style='color:red'>)" ,
  825.                                                   $SKIN->form_input("prefix", $prefix )
  826.                                          )      );
  827.                                          
  828.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Online List Format [Suffix]</b><br>(Can be left blank)<br>(Example:</span>)" ,
  829.                                                   $SKIN->form_input("suffix", $suffix )
  830.                                          )      );
  831.                                          
  832.         $ADMIN->html .= $SKIN->end_table();
  833.         
  834.         //+-------------------------------
  835.         
  836.         $SKIN->td_header[] = array( " "  , "40%" );
  837.         $SKIN->td_header[] = array( " "  , "60%" );
  838.         
  839.         //+-------------------------------
  840.         
  841.         $ADMIN->html .= $SKIN->start_table( "Global Permissions" );
  842.         
  843.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can view board?</b>" ,
  844.                                                   $SKIN->form_yes_no("g_view_board", $group['g_view_board'] )
  845.                                          )      );
  846.                                          
  847.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can view OFFLINE board?</b>" ,
  848.                                                   $SKIN->form_yes_no("g_access_offline", $group['g_access_offline'] )
  849.                                          )      );
  850.         
  851.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can view member profiles and the member list?</b>" ,
  852.                                                   $SKIN->form_yes_no("g_mem_info", $group['g_mem_info'] )
  853.                                          )      );
  854.                                          
  855.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can view other members topics?</b>" ,
  856.                                                   $SKIN->form_yes_no("g_other_topics", $group['g_other_topics'] )
  857.                                          )      );
  858.                                          
  859.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can use search?</b>" ,
  860.                                                   $SKIN->form_yes_no("g_use_search", $group['g_use_search'] )
  861.                                          )      );                                 
  862.                                          
  863.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can mail members from the board?</b>" ,
  864.                                                   $SKIN->form_yes_no("g_email_friend", $group['g_email_friend'] )
  865.                                          )      );
  866.                                          
  867.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can edit own profile info?$guest_legend" ,
  868.                                                   $SKIN->form_yes_no("g_edit_profile", $group['g_edit_profile'] )
  869.                                          )      );                                 
  870.                                          
  871.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can use PM system?$guest_legend" ,
  872.                                                   $SKIN->form_yes_no("g_use_pm", $group['g_use_pm'] )
  873.                                          )      );
  874.                                                                                                        
  875.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can Upload avatars?$guest_legend" ,
  876.                                                   $SKIN->form_yes_no("g_avatar_upload", $group['g_avatar_upload'] )
  877.                                          )      );
  878.                                          
  879.         $ADMIN->html .= $SKIN->end_table();
  880.         
  881.         //+-------------------------------
  882.         
  883.         $SKIN->td_header[] = array( " "  , "40%" );
  884.         $SKIN->td_header[] = array( " "  , "60%" );
  885.         
  886.         //+-------------------------------
  887.         
  888.         $ADMIN->html .= $SKIN->start_table( "Posting Permissions" );
  889.         
  890.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can post new topics (where allowed)?</b>" ,
  891.                                                   $SKIN->form_yes_no("g_post_new_topics", $group['g_post_new_topics'] )
  892.                                          )      );
  893.         
  894.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can reply to OWN topics?</b>" ,
  895.                                                   $SKIN->form_yes_no("g_reply_own_topics", $group['g_reply_own_topics'] )
  896.                                          )      );
  897.         
  898.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can reply to OTHER members topics (where allowed)?</b>" ,
  899.                                                   $SKIN->form_yes_no("g_reply_other_topics", $group['g_reply_other_topics'] )
  900.                                          )      );
  901.         
  902.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can edit own posts?$guest_legend" ,
  903.                                                   $SKIN->form_yes_no("g_edit_posts", $group['g_edit_posts'] )
  904.                                          )      );
  905.                                          
  906.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Append 'Edited by' legend?</b>" ,
  907.                                                   $SKIN->form_yes_no("g_append_edit", $group['g_append_edit'] )
  908.                                          )      );                                 
  909.                                          
  910.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can delete own posts?$guest_legend" ,
  911.                                                   $SKIN->form_yes_no("g_delete_own_posts", $group['g_delete_own_posts'] )
  912.                                          )      );
  913.                                                                       
  914.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can open/close own topics?$guest_legend" ,
  915.                                                   $SKIN->form_yes_no("g_open_close_posts", $group['g_open_close_posts'] )
  916.                                          )      );                                 
  917.         
  918.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can delete own topics?$guest_legend" ,
  919.                                                   $SKIN->form_yes_no("g_delete_own_topics", $group['g_delete_own_topics'] )
  920.                                          )      );
  921.         
  922.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can start new polls (where allowed)?$guest_legend</b>" ,
  923.                                                   $SKIN->form_yes_no("g_post_polls", $group['g_post_polls'] )
  924.                                          )      );
  925.                                          
  926.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can vote in polls (where allowed)?$guest_legend" ,
  927.                                                   $SKIN->form_yes_no("g_vote_polls", $group['g_vote_polls'] )
  928.                                          )      );                                 
  929.                                          
  930.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can avoid flood control?</b>" ,
  931.                                                   $SKIN->form_yes_no("g_avoid_flood", $group['g_avoid_flood'] )
  932.                                          )      );
  933.                                          
  934.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can avoid moderation queues?</b>" ,
  935.                                                   $SKIN->form_yes_no("g_avoid_q", $group['g_avoid_q'] )
  936.                                          )      );
  937.                                          
  938.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can add events to the calendar?$guest_legend</b>" ,
  939.                                                   $SKIN->form_yes_no("g_calendar_post", $group['g_calendar_post'] )
  940.                                          )      );
  941.                                                                                                    
  942.         $ADMIN->html .= $SKIN->end_table();
  943.         
  944.         //+-------------------------------
  945.         
  946.         $SKIN->td_header[] = array( " "  , "40%" );
  947.         $SKIN->td_header[] = array( " "  , "60%" );
  948.         
  949.         //+-------------------------------
  950.         
  951.         $ADMIN->html .= $SKIN->start_table( "Moderation Permissions" );
  952.         
  953.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Is Super Moderator (can moderate anywhere)?$guest_legend" ,
  954.                                                   $SKIN->form_yes_no("g_is_supmod", $group['g_is_supmod'] )
  955.                                          )      );
  956.         
  957.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Can access the Admin CP?$guest_legend" ,
  958.                                                   $SKIN->form_yes_no("g_access_cp", $group['g_access_cp'] )
  959.                                          )      );
  960.                                          
  961.         $ADMIN->html .= $SKIN->end_form($button);
  962.                                          
  963.         $ADMIN->html .= $SKIN->end_table();
  964.         
  965.         $ADMIN->output();
  966.             
  967.             
  968.     }
  969.  
  970.     //+---------------------------------------------------------------------------------
  971.     //
  972.     // Show "Management Screen
  973.     //
  974.     //+---------------------------------------------------------------------------------
  975.     
  976.     function main_screen()
  977.     {
  978.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  979.         
  980.         $ADMIN->page_title = "User Groups";
  981.         
  982.         $ADMIN->page_detail = "User Grouping is a quick and powerful way to organise your members. There are 4 preset groups that you cannot remove (Validating, Guest, Member and Admin) although you may edit these at will. A good example of user grouping is to set up a group called 'Moderators' and allow them access to certain forums other groups do not have access to.<br>Forum access allows you to make quick changes to that groups forum read, write and reply settings. You may do this on a forum per forum basis in forum control.";
  983.         
  984.         $g_array = array();
  985.         
  986.         $SKIN->td_header[] = array( "Group Title"    , "30%" );
  987.         $SKIN->td_header[] = array( "ACP"            , "5%" );
  988.         $SKIN->td_header[] = array( "SMOD"           , "5%" );
  989.         $SKIN->td_header[] = array( "Members"        , "10%" );
  990.         $SKIN->td_header[] = array( "Edit Group"     , "20%" );
  991.         $SKIN->td_header[] = array( "Forum Access"   , "20%" );
  992.         $SKIN->td_header[] = array( "Delete"         , "10%" );
  993.         
  994.         //+-------------------------------
  995.         
  996.         $ADMIN->html .= $SKIN->start_table( "User Group Management" );
  997.         
  998.         $DB->query("SELECT ibf_groups.g_id, ibf_groups.g_access_cp, ibf_groups.g_is_supmod, ibf_groups.g_title,ibf_groups.prefix, ibf_groups.suffix, COUNT(ibf_members.id) as count FROM ibf_groups "
  999.                   ."LEFT JOIN ibf_members ON (ibf_members.mgroup = ibf_groups.g_id) "
  1000.                   ."GROUP BY ibf_groups.g_id ORDER BY ibf_groups.g_title");
  1001.         
  1002.         while ( $r = $DB->fetch_row() )
  1003.         {
  1004.         
  1005.             $del  = "";
  1006.             $mod  = ' ';
  1007.             $adm  = ' ';
  1008.             
  1009.             if ($r['g_id'] > 4)
  1010.             {
  1011.                 $del = "<center><a href='{$ADMIN->base_url}&act=group&code=delete&id=".$r['g_id']."'>Delete</a></center>";
  1012.             }
  1013.             //-----------------------------------
  1014.             if ($r['g_access_cp'] == 1)
  1015.             {
  1016.                 $adm = '<center><span style="color:red">Y</span></center>';
  1017.             }
  1018.             //-----------------------------------
  1019.             if ($r['g_is_supmod'] == 1)
  1020.             {
  1021.                 $mod = '<center><span style="color:red">Y</span></center>';
  1022.             }
  1023.             
  1024.             if ($r['g_id'] != 1 and $r['g_id'] != 2)
  1025.             {
  1026.                 $total_linkage = "<a href='{$INFO['board_url']}/index.{$INFO['php_ext']}?act=Members&max_results=30&filter={$r['g_id']}&sort_order=asc&sort_key=name&st=0' target='_blank' title='List Users'>".$r['prefix'].$r['g_title'].$r['suffix']."</a>";
  1027.             }
  1028.             else
  1029.             {
  1030.                 $total_linkage = $r['prefix'].$r['g_title'].$r['suffix'];
  1031.             }
  1032.             
  1033.             $ADMIN->html .= $SKIN->add_td_row( array( "<b>$total_linkage</b>" ,
  1034.                                                       $adm,
  1035.                                                       $mod,
  1036.                                                       "<center>".$r['count']."</center>",
  1037.                                                       "<center><a href='{$ADMIN->base_url}&act=group&code=edit&id=".$r['g_id']."'>Edit Group</a></center>",
  1038.                                                       "<center><a href='{$ADMIN->base_url}&act=group&code=fedit&id=".$r['g_id']."'>Forum Access</a></center>",
  1039.                                                       $del
  1040.                                                       
  1041.                                          )      );
  1042.                                          
  1043.             $g_array[] = array( $r['g_id'], $r['g_title'] );
  1044.         }
  1045.         
  1046.         $ADMIN->html .= $SKIN->add_td_basic(" ", "center", "title");
  1047.  
  1048.         $ADMIN->html .= $SKIN->end_table();
  1049.         
  1050.         //+-------------------------------
  1051.         
  1052.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'add' ),
  1053.                                                   2 => array( 'act'   , 'group'     ),
  1054.                                          )      );
  1055.                                          
  1056.         //+-------------------------------
  1057.         
  1058.         $SKIN->td_header[] = array( " "  , "40%" );
  1059.         $SKIN->td_header[] = array( " "  , "60%" );
  1060.         
  1061.         //+-------------------------------
  1062.         
  1063.         $ADMIN->html .= $SKIN->start_table( "Add a new member group" );
  1064.         
  1065.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Base new group on...</b>" ,
  1066.                                                   $SKIN->form_dropdown("id", $g_array, 3 )
  1067.                                          )      );
  1068.                                          
  1069.         $ADMIN->html .= $SKIN->end_form("Set up New Group");
  1070.                                          
  1071.         $ADMIN->html .= $SKIN->end_table();
  1072.         
  1073.         $ADMIN->output();
  1074.         
  1075.         
  1076.     }
  1077.     
  1078.         
  1079. }
  1080.  
  1081.  
  1082. ?>